package com.ak.haomatong.activity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.app.ListActivity;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;


/**
 * @ClassName:  CallRecordAcitivity.java
 * @Description: 
 * @Author JinChao
 * @Date 2013-2-17 下午4:49:03
 * @Copyright: 版权由 HundSun 拥有
 */
public class CallRecordActivity extends ListActivity
{
    Context                       mContext                  = null;
    ListView                      mListView                 = null;
    MyListAdapter                 myAdapter                 = null;
    
    
    private ArrayList<CallRecord> callRecordList = new ArrayList<CallRecord>();
    
    public void onCreate(Bundle savedInstanceState)
    {
        mContext = this;
        mListView = this.getListView();
        
        myAdapter = new MyListAdapter(this);
        setListAdapter(myAdapter);
        
        
        
    }
    
    private void getCallRecord(){
        String str = "";
        int type;
        long callTime;
        Date date;
        String time= "";
        ContentResolver cr = getContentResolver();
        final Cursor cursor = cr.query(CallLog.Calls.CONTENT_URI, new String[]{CallLog.Calls.NUMBER,CallLog.Calls.CACHED_NAME,CallLog.Calls.TYPE, CallLog.Calls.DATE}, null, null,CallLog.Calls.DEFAULT_SORT_ORDER);
                for (int i = 0; i < cursor.getCount(); i++) {  
                    cursor.moveToPosition(i);
                    str = cursor.getString(0);
                    str = cursor.getString(1);
                    type = cursor.getInt(2);
                    SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
                    date = new Date(Long.parseLong(cursor.getString(3)));
                    time = sfd.format(date);
        }
    }
    
    class MyListAdapter extends BaseAdapter {
        public MyListAdapter(Context context) {
            mContext = context;
        }

        public int getCount() {
            //设置绘制数量
            return callRecordList.size();
        }

        @Override
        public boolean areAllItemsEnabled() {
            return false;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView iamge = null;
            TextView title = null;
            TextView text = null;
            if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(
                R.layout., null);
            iamge = (ImageView) convertView.findViewById(R.id.color_image);
            title = (TextView) convertView.findViewById(R.id.color_title);
            text = (TextView) convertView.findViewById(R.id.color_text);
            }
            //绘制联系人名称
            title.setText(mContactsName.get(position));
            //绘制联系人号码
            text.setText(mContactsNumber.get(position));
            //绘制联系人头像
            iamge.setImageBitmap(mContactsPhonto.get(position));
            return convertView;
        }

        }
    class CallRecord{
        //0:未接  1：接通电话  2：呼叫电话
        public int status=-1;
        public String name;
        public String phoneNumber;
        public long time;
        
        
    }
    
}
